import { GetMapping, PostMapping, RestController } from "../decorator";
import { File } from "node:buffer";
import { Autowired } from "../ioc";
import FileService from "../service/FileService";

@RestController("/file")
class FileController {
  @Autowired()
  private fileService: FileService;

  constructor(fileService: FileService) {
    console.log("FileController constructor");
    this.fileService = fileService;
  }

  @GetMapping("/download")
  downloadFile() {
    // const filePath = "uploads/abc.txt";
    // console.log(filePath);
    // return "file:" + filePath;
    return this.fileService.downloadFile();
  }

  @PostMapping("/fileUpload", true)
  saveFile(file: File): string {
    // console.log(file);
    this.fileService.saveFile(file);
    return "文件上传成功";
  }
}

// export default new FileController();
export default FileController;
